package com.zheng.study.web.shiro.filter;

import com.zheng.study.company.service.AdminService;
import com.zheng.study.company.service.UserService;
import com.zheng.study.web.shiro.Constants;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.web.filter.PathMatchingFilter;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * 当前登录人员
 * ============================================================================
 * author : User: Zhang Kaitao
 * createDate: 14-2-15
 * ============================================================================
 */
public class SysUserFilter extends PathMatchingFilter {

	@Autowired
	private UserService userService;

	@Override
	protected boolean onPreHandle(ServletRequest request, ServletResponse response, Object mappedValue){
		String adminId = (String) SecurityUtils.getSubject().getPrincipal();
		request.setAttribute(Constants.CURRENT_USER, userService.getUserByAdminId(adminId));
		return true;
	}

}
